package FlyweightMod;

import FlyweightMod.code.Account;
import java.util.HashMap;
import java.util.Map;

// 账户工厂类
public class AccountFactory {

    private static AccountFactory singleton = new AccountFactory();

    private Map<String, Account> pool = new HashMap<>();

    private AccountFactory() {
    }

    public static AccountFactory getInstance() {
        return singleton;
    }

    public Account getAccount(String permission) {
        if (!pool.containsKey(permission)) {
            // 根据权限类型创建不同的账户对象
            code code = new code();
            Account account;
            if (permission.equals("SuperVIP")) {
                account = code.new SuperVIP(permission);
            } else if (permission.equals("VIP")) {
                account = code.new VIP(permission);
            } else {
                account = code.new Normal(permission);
            }
            pool.put(permission, account);
        }
        return pool.get(permission);
    }
}
